<?php
class UserPasswordController extends Zone_Action{
	public function indexAction(){
		$this->removeLayout();
		$user_id = get_user_id();
		$oldpass = $this->Model->fetchOne("SELECT `password` 
			FROM `users` WHERE `ID`='$user_id'");
		$fields  = array(
			password => array(
				type		=> 'PASSWORD',
				form_label	=> 'Mật khẩu',
				no_empty	=> true,
				old_value	=> $oldpass,
				min_length	=> 6,
				max_length	=> 100
			)	
		);
		
		loadClass('ZData');
		$f = new ZData();
		$f->addField($fields);
		if( isPost() ){
			$data = $f->getData();
			if(!is_array( $data )){
				return $this->setJSON(array(
					message	=> error($data)
				));
			}		
			$this->Model->update("users",$data,"`ID`='$user_id'");
			return $this->setJSON(array(
				callback => "(function(){
					location.href='".baseUrl()."/Logout';
				})()"	
			));			
		}
	}
}	